package com.letu.core.exception.code;


import com.letu.annotation.base.LanguageTypeEnum;
import com.letu.core.context.ContextUtil;

/**
 * 异常编码
 *
 * @author ligang
 * @date 2017-12-13 16:22
 */
public enum ExceptionCode implements BaseExceptionCode {

    //系统相关 start
    SUCCESS(1, "成功","success"),
    SYSTEM_BUSY(-1, "系统繁忙~请稍后再试~","System busy ~ Please try again later"),
    SYSTEM_TIMEOUT(-2, "系统维护中~请稍后再试~","System maintenance ~ Please try again later"),
    PARAM_EX(-3, "参数类型解析异常","Parameter type resolution exception"),
    SQL_EX(-4, "运行SQL出现异常","An exception occurs during SQL running. Procedure"),
    NULL_POINT_EX(-5, "空指针异常","null pointer exception"),
    ILLEGAL_ARGUMENT_EX(-6, "无效参数异常","Invalid parameter exception"),
    MEDIA_TYPE_EX(-7, "请求类型异常","Request type exception"),
    LOAD_RESOURCES_ERROR(-8, "加载资源出错","Load resources exception"),
    BASE_VALID_PARAM(-9, "统一验证参数异常","Unified verification parameters exception"),
    OPERATION_EX(-10, "操作异常","handle exception"),
    SERVICE_MAPPER_ERROR(-11, "Mapper类转换异常","mapper convert exception"),
    CAPTCHA_ERROR(-12, "验证码校验失败","Verification code exception"),
    JSON_PARSE_ERROR(-13, "JSON解析异常","json parse exception"),
    PROJECT_ID_ERROR(-14, "项目id不能为空","projectId is null"),

    TENANT_ID_ERROR(-15, "租户ID不能为空","projectId is null"),
    SUBMIT_AGAIN(-16, "请勿重复提交","submit again"),

    NO_PERMISSION(-17, "没有权限","Invalid parameter exception"),

    TOEKN_ERROR(-18, "token失效","Invalid parameter exception"),

    OK(200, "OK","OK"),
    BAD_REQUEST(400, "错误的请求","Bad"),
    /**
     * {@code 401 Unauthorized}.
     *
     * @see <a href="http://tools.ietf.org/html/rfc7235#section-3.1">HTTP/1.1: Authentication, section 3.1</a>
     */
    UNAUTHORIZED(401, "未认证的","unverified"),
    FORBIDDEN(403, "被禁止的","under embargo"),
    /**
     * {@code 404 Not Found}.
     *
     * @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.4">HTTP/1.1: Semantics and Content, section 6.5.4</a>
     */
    NOT_FOUND(404, "没有找到资源","no find resource"),
    METHOD_NOT_ALLOWED(405, "不支持当前请求类型","request type is not supported"),

    TOO_MANY_REQUESTS(429, "请求超过次数限制","The number of requests exceeded the limit"),
    INTERNAL_SERVER_ERROR(500, "内部服务错误","Internal service error"),
    BAD_GATEWAY(502, "网关错误","gateway error"),
    GATEWAY_TIMEOUT(504, "网关超时","gateway timeout"),
    //系统相关 end

    REQUIRED_FILE_PARAM_EX(1001, "请求中必须至少包含一个有效文件","The request must contain at least one valid file"),

    DATA_SAVE_ERROR(2000, "新增数据失败","add error"),
    DATA_UPDATE_ERROR(2001, "修改数据失败","upd error"),
    TOO_MUCH_DATA_ERROR(2002, "批量新增数据过多","Too much data is added in batches"),

    //菜单相关
    MENU_PARAM_ERROR(3001,"菜单参数错误","Menu parameter error"),

    //jwt token 相关 start

    JWT_BASIC_INVALID(40000, "无效的基本身份验证令牌","Invalid basic authentication token"),
    JWT_TOKEN_EXPIRED(40001, "会话超时，请重新登录","Session timed out. Please log in again"),
    JWT_SIGNATURE(40002, "不合法的token，请认真比对 token 的签名","An invalid token  "),
    JWT_ILLEGAL_ARGUMENT(40003, "缺少token参数","Missing token parameter  "),
    JWT_GEN_TOKEN_FAIL(40004, "生成token失败","Failed to generate token  "),
    JWT_PARSER_TOKEN_FAIL(40005, "解析用户身份错误，请重新登录！","User identity parsing error"),
    JWT_USER_INVALID(40006, "用户名或密码错误","The user name or password is incorrect"),
    JWT_USER_ENABLED(40007, "用户已经被禁用！","The user has been disabled"),
    JWT_OFFLINE(40008, "您已在另一个设备登录！","You are logged in on another device"),
    JWT_NOT_LOGIN(40009, "登录超时，请重新登录！","Login timed out. Please log in again"),
    //jwt token 相关 end
    USER_NO_ERROR(40010, "用户不存在","The user does not exist"),
    LOGINNAME_AGAIN(40011, "登录名已存在","The login name already exists"),
    CHILD_DELETE_NO(40012, "存在可用子节点，不允许删除","Child nodes are available and cannot be deleted"),
    NODE_ADD_NO(40013, "节点组织组已存在","The node organization group already exists"),
    ID_CARD_NO(40014, "未检测到信息","No message was detected"),
    NODE_NO(40015, "节点组织不存在","The node organization does not exist"),
    MEUN_MORE(40016, "菜单超出范围","Menu out of range"),
    FUNCTION_MORE(40017, "事件超出范围","Event out of range"),
    SYS_ORG_NULL(40018, "登录场景为空","login scene is null"),
    MOBILE_AGAIN(40019, "手机号已存在","The mobile already exists"),
    EMIAL_AGAIN(40020, "邮箱已存在","The email already exists"),

    //auth相关
    ORG_ADD_USER_ERROR(41001, "添加用户失败","add user is error"),
    ORG_NULL(41002, "组织不存在","org is null"),
    USER_NO_ENABLED(40021, "用户已锁定","The user does not exist"),
    PRIVATE_KEY(40030, "私钥key失效","The user does not exist"),
    USER_MOBILE_AGAIN(40022, "用户手机号或账号已存在","The user does not exist"),
    //预登记相关
    VISITOR_MOBILE_ERROR(40018, "手机号与账号不一致","mobile phone number is inconsistent with the account number"),
    VISITOR_EMAIL_ERROR(40019, "邮箱与账号不一致","The email address is inconsistent with the account"),
    VISITOR_INFO_ERROR(40020, "必填项校验未通过","The mandatory item fails to pass the verification"),
    VISITOR_NULL(400021,"观众不存在","The audience doesn't exist"),

    //展商展品产品相关
    PRODUCT_OFFLINE(50001,"此展品已下架","The exhibit has been removed from the shelves"),
    PRODUCT_AUDIT_LOCKING(50002,"此展品已经提交审核，审核完成之前不可编辑","This exhibit has been submitted for review"),

    //公司员工相关
    EMPLOYEE_EXIST(60001,"已经是公司员工","Already an employee of the company"),
    COMPANY_CHECK_FAIL(60002,"公司审核失败","Company audit failure"),
    EMPLOYEE_CHECK_FAIL(60003,"用户加入公司失败","The user failed to join the company. Procedure"),
    COMPANY_ERROR(60004,"公司信息冲突","Corporate information conflict"),
    ALREADY_CHECK(60005,"用户已有审核，不能操作","User existing audit"),
    COMPANY_NULL(60006,"公司不存在","The company doesn't exist"),
    COMPANY_NO_AUTH(60007,"公司未认证","Company not certified"),

    //收藏
    COLLECTION_REPEAT(61001,"重复收藏","Repeat collection"),
    //邀约
    APPOINTMENT_REPEAT(62001,"重复邀约","Repeated invitation"),

    //会展模块相关
    EXHIBITOR_NULL(70001,"展商不存在","Repeat invitation for exhibitors does not exist"),
    CUSTOMER_NAME_EXIST(70002,"客户名称已存在","The customer name already exists"),



    //参数相关
    ERROR_NULL_ID(90001,"id不能为空","Id cannot be empty"),
    ERROR_NULL_PARAMS(90002,"参数错误","parameter error"),

    ERROR_VERIFY(90003,"校验错误","parameter error"),
    ERROR_FORM_FIELD_CLASS_NAME(90004,"表单配置项异常，未配置类名","form field class name error"),
    ERROR_FORM_FIELD_CAST(90005,"表单配置类型转换异常","form field cast error"),
    ERROR_FORM_FIELD_CAST_NOT_FOUND(90006,"表单配置转实体失败，未找到","form field cast class error, not found"),
    ;

    private final int code;
    //中文消息
    private String msg;
    //英文消息
    private String enMsg;

    ExceptionCode(int code, String msg,String enMsg) {
        this.code = code;
        this.msg = msg;
        this.enMsg = enMsg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }


    public ExceptionCode build(String msg, Object... param) {
        this.msg = String.format(msg, param);
        return this;
    }

    public ExceptionCode param(Object... param) {
        msg = String.format(msg, param);
        return this;
    }
}
